package com.miaosha.ms_03.dao;

import com.miaosha.ms_03.domain.OrderInfo;
import org.apache.ibatis.annotations.*;

/**
 * @Description //TODO
 * @Author Administrator
 * @DATE 2020/9/19 15:23
 **/
@Mapper
public interface OrderDao {

    @Insert("INSERT INTO order_info (USER_ID,GOODS_ID,DELIVERY_ADDR_ID,GOODS_NAME,GOODS_COUNT,GOODS_PRICE," +
            "ORDER_CHANNEL,STATUS,CREATE_DATE,PAY_DATE) VALUES(#{userId},#{goodsId},#{deliveryAddrId},#{goodsName}," +
            "#{goodsCount},#{goodsPrice},#{orderChannel},#{status},#{createDate},#{payDate})")
    @Options(keyColumn = "id", keyProperty = "id", useGeneratedKeys = true)
    Long insert(OrderInfo orderInfo);

    @Select("SELECT * FROM order_info WHERE ID = #{id}")
    OrderInfo getOrderInfoById(@Param("orderId") Long orderId);

    @Select("SELECT COUNT(*) FROM order_info WHERE USER_ID = #{userId} AND GOODS_ID =#{goodsId}")
    Integer countByUserIdAndGoodsId(Long userId, Long goodsId);
}
